package com.project.dao.impl;

import com.project.bean.UserBean;

import java.sql.*;

/**
 * 所有的DAO的父类
 */
public class BaseDao {
//    链接对象
   protected Connection con;
//   SQL语句执行对象
   protected PreparedStatement ps;
//   结果集
   protected ResultSet rs;

    /**
     * 建立链接
     */
   public void setConnection(){

       try {
           Class.forName("com.mysql.jdbc.Driver");
           con = DriverManager.getConnection("jdbc:mysql://localhost:12345/db?characterEncoding=utf-8","root","lovo");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
   public void closeConnection(){

       try {
           if (rs!=null){
           rs.close();
           }
           if (ps !=null){
               ps.close();
           }
           if (con !=null){
               con.close();
           }
       } catch (SQLException e) {
           e.printStackTrace();
       }

   }

}
